home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 4 / QRZ Ham Radio Callsign Database - Volume 4.iso / files / loggers / qrate.exe / RATE.C < prev    next >
Text File  |  1993-08-28  |  4KB  |  155 lines

  1. /*
  2.     RATE calculator for CT and other similar log files
  3.     by Peter Jennings VE3SUN    72470.3171@compuserve.com
  4.  
  5.     Released to the Public Domain 1993.
  6.  
  7.     Compiled with Turbo C 2.0 - any model.
  8. */
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <ctype.h>
  14.  
  15. main (int argc,char *argv[])
  16. {
  17. FILE *ptr1;
  18. FILE *ptr2;
  19. char record[256];
  20. long incnt = 0;
  21. long qcnt=0;
  22. int offset = 0;
  23. int time,ltime=-1,minute,i,rate1,rate10,rate60,wminute,mtime;
  24. int max1=0, max10=0, max60=0;
  25. int tmax1=0,tmax10=0,tmax60=0;
  26. long minutes[60],hrago=0;
  27. char *p;
  28.  
  29. if ( argc < 3 )
  30.     {
  31.     printf( "\nRATE infile reportfile [offset]\n\n"
  32.             "Calculates QSO rates for 1 minute, 10 minutes, and 1 hour.\n\n"
  33.             "infile     is any file with 4 digit times beginning at column [offset]\n\n"
  34.             "reportfile will be created or appended to.\n\n"
  35.             "offset     is an optional column offset to the time column (0 origin).\n"
  36.             "           not needed for CT   *.ASC   *.RES   *.ALL files.\n");
  37.     exit(1);
  38.     }
  39. if ((ptr1 = fopen(argv[1],"r"))==NULL)
  40.     {
  41.     printf("\nUnable to open %s\n",argv[1]);
  42.     exit(1);
  43.     }
  44. if ((ptr2 = fopen(argv[2],"a"))==NULL)
  45.     {
  46.     printf("\nUnable to create %s\n",argv[2]);
  47.     exit(1);
  48.     }
  49. offset = 0;
  50.  
  51. if ( strstr(strupr(argv[1]),".RES") ) offset = 9;
  52. if ( strstr(argv[1],".ALL") ) offset = 15;
  53. if ( strstr(argv[1],".ASC") ) offset = 25;
  54.  
  55. if ( argc > 3 ) offset = atoi(argv[3]);
  56.  
  57. printf("\n\nTime field offset for %s is %d\n\n",argv[1],offset);
  58.  
  59. for(i=0; i<60; i++)
  60.     minutes[i] = 0;
  61.  
  62. while(1)
  63.     {
  64.     memset(record,0,256);
  65.     if ( fgets(record,256,ptr1) == NULL ) break;
  66.     incnt++;
  67.     if ( qcnt < 5 )
  68.         {
  69.         printf("%s",record);
  70.         fprintf(ptr2,"%s",record);
  71.         }
  72.     if ( qcnt ==5 )
  73.         {
  74.         for( i=0; i<offset; i++) printf(" ");
  75.         printf("^^^^");
  76.         printf("\n\nPress any key to continue....     Esc to quit.\n\n");
  77.         if ( 0x1b == getch()) exit(1);
  78.         }
  79.     p = strtok(record+offset," \t\n\r");
  80. /**********/
  81.     if ( strlen(p) < 3 || strlen(p) >4 ) continue;
  82.     if ( !isdigit(p[0]) || !isdigit(p[1]) || !isdigit(p[2]) || !isdigit(p[3]) ) continue;
  83.     qcnt++;
  84.     time = atoi(p);
  85.     mtime = 60*(time/100)+time%100;
  86.     if ( ltime > mtime )            /* the next day begins */
  87.         mtime = mtime + 1440;
  88.  
  89.     if ( (mtime - ltime) > 1 )
  90.         {
  91.         for( i=ltime+1; i < mtime; i++)
  92.             minutes[i%60] = minutes[ltime%60];
  93.         }
  94.     minute = atoi(p+2);
  95.  
  96.     if ( mtime%1440 != ltime )
  97.         hrago = minutes[ minute ];
  98.  
  99.     ltime = mtime%1440;
  100.  
  101.     minutes[ minute ] = qcnt;
  102.  
  103.     wminute = minute-1;
  104.     if ( wminute < 0 ) wminute += 60;
  105.  
  106.     rate1 = qcnt-minutes[wminute];
  107.  
  108.     if ( rate1 > max1 )
  109.         {
  110.         max1 = rate1;
  111.         tmax1 = time;
  112.         if ( qcnt > 10 )
  113.             printf("%10.04d %10d* %10d  %10d \n",time,max1,max10,max60);
  114.         }
  115.  
  116.     wminute = minute-10;
  117.     if ( wminute < 0 ) wminute += 60;
  118.     rate10 = qcnt-minutes[wminute];
  119.     if ( rate10 > max10 )
  120.         {
  121.         max10 = rate10;
  122.         tmax10 = time;
  123.         if ( qcnt > 20 )
  124.             printf("%10.04d %10d  %10d* %10d \n",time,max1,max10,max60);
  125.         }
  126.  
  127.     rate60 = qcnt - hrago;
  128.     if ( rate60 > max60 )
  129.         {
  130.         max60 = rate60;
  131.         tmax60 = time;
  132.         if ( mtime > 60 && qcnt > 20 )
  133.             printf("%10.04d %10d  %10d  %10d*\n",time,max1,max10,max60);
  134.         }
  135.  
  136.     }
  137. fclose(ptr1);
  138. printf(    "\n%12ld records read from %s\n" ,
  139.         incnt, argv[1] );
  140. printf("\n%10.04d: %10d per minute     (%d/hr)\n",tmax1,max1,max1*60);
  141. printf("%10.04d: %10d per 10 minutes (%d/hr)\n",tmax10,max10,max10*6);
  142. printf("%10.04d: %10d per hour\n",tmax60,max60);
  143. printf("\nTotal Qs: %10ld  Average %10ld per hour\n\n",qcnt,qcnt/48);
  144.  
  145. fprintf(ptr2,    "\n%12ld records read from %s\n" ,
  146.         incnt, argv[1] );
  147. fprintf(ptr2,"\n%10.04d: %10d per minute     (%d/hr)\n",tmax1,max1,max1*60);
  148. fprintf(ptr2,"%10.04d: %10d per 10 minutes (%d/hr)\n",tmax10,max10,max10*6);
  149. fprintf(ptr2,"%10.04d: %10d per hour\n",tmax60,max60);
  150. fprintf(ptr2,"\nTotal Qs: %ld  Average rate: %ld per hour\n\n",qcnt,qcnt/48);
  151. fprintf(ptr2,"--------------------------------------------------\n");
  152. fclose(ptr2);
  153. }
  154.  
  155.